package gatperdut.chato.lucene.parser.commands;

import gatperdut.chato.constants.CSConstantsLucene;
import gatperdut.chato.lucene.parser.CMParser;
import gatperdut.chato.lucene.parseresult.commands.CommandParseResult;

import java.io.File;
import java.io.FileNotFoundException;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.XMLEvent;

public class CommandsParser extends CMParser {

    public CommandsParser( File fileToParse ) throws FileNotFoundException, XMLStreamException {
        super( fileToParse, new CommandParseResult() );
    }

    @Override
    public void dealWithEvent( XMLEvent event ) throws XMLStreamException {

        if ( event.asStartElement().getName().getLocalPart().equals( CSConstantsLucene.FIELD_USAGE ) ) {
            event = getEventReader().nextEvent();
            String usage = event.asCharacters().getData();
            getParseResult().setUsage( usage );
            getParseResult().getCatchAll().append( usage + " " );
        }

    }

    @Override
    public CommandParseResult getParseResult() {
        return (CommandParseResult) super.getParseResult();
    }

}
